﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel.DataAnnotations;
using FIFP.DashBoard.Helper;
using FIFP.DashBoard.ViewModel;

namespace FIFP.DashBoard.Converters
{
    public class ErrorValidation
    {
        public static ValidationResult ValidateScenario(string scenarioName, ValidationContext context)
        {
            if (string.IsNullOrEmpty(scenarioName))
                return new ValidationResult("Must Enter Scenario Name", new[] { context.MemberName });
            else if (!string.IsNullOrEmpty(scenarioName) && ServiceLocator.Get<ImportVM>().IsScenarioExist)
                return new ValidationResult("The Entered Scenario name has already exist. Enter different scenario name", new[] { context.MemberName });
            else
                return ValidationResult.Success;
        }

        public static ValidationResult ValidateUnitName(string unitName, ValidationContext context)
        {
            if (string.IsNullOrEmpty(unitName))
                return new ValidationResult("Enter UnitName", new[] { context.MemberName });
            else if (!string.IsNullOrEmpty(unitName) && (ServiceLocator.Get<ImportVM>().IsUnitNameExist || ServiceLocator.Get<ShutdownMngVM>().IsUnitNameExist))
                return new ValidationResult("UnitName does not exist", new[] { context.MemberName });
            else
                return ValidationResult.Success;
        }

        public static ValidationResult ValidatePercentage(int percentage, ValidationContext context)
        {
            if (percentage >= 0 && percentage <= 100)
                return ValidationResult.Success;
            else
                return new ValidationResult("Enter percentage value between 0 to 100", new[] { context.MemberName });
        }
    }
}
